home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
051-075
/
scopedisk52
/
xlisp
/
hanoi.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1995-03-18
|
448b
|
25 lines
; Good ol towers of hanoi
;
; Usage:
; (hanoi <n>)
; <n> - an integer the number of discs
(defun hanoi(n)
( transfer 'A 'B 'C n ))
(defun print-move ( from to )
(princ "Move Disk From ")
(princ from)
(princ " To ")
(princ to)
(princ "\n"))
(defun transfer ( from to via n )
(cond ((equal n 1) (print-move from to ))
(t (transfer from via to (- n 1))
(print-move from to)
(transfer via to from (- n 1)))))